import React, { Component } from 'react';
import { Row, Col, Icon } from 'antd';
import {Link} from 'react-router-dom';
import Mutil from '../../util/mm.js';
import User from '../../server/user-server.js';
import './index.less';
const _mm = new Mutil();
const _user = new User();


class Header extends Component {
	constructor(props){
		super(props);
		this.state = {
			userName: _mm.getStorage('userInfo').username
		}
	}
  onLogout = () => {
    _user.logout().then(res=>{
      _mm.removeStorage('userInfo');
      // window.localtion.href = '/login';
    }, errMsg => {
      _mm.errorTips(errMsg);
    })
  }
  render() {
    return (
      <div className="header">
      	<Row className="header-top">
      		<Col span="24">
      			{
              this.state.userName
              ? <span><Icon type="user" />欢迎,{this.state.userName}</span>
              : <span><Icon type="user" />欢迎您</span>
            }
      			<Link to="/login" onClick={this.onLogout} href="">退出</Link>
      		</Col>
      	</Row>
      </div>
    );
  }
}

export default Header;
